<?php
	session_start();
	require_once('functions.php');
	
	if( $_SESSION['account_type_code'] != 1 && $_SESSION['account_type_code'] != 2) 
	{
		header("Location:index.php?response_msg=Please login.");
		exit;
	}
	
	$sailor_id = $_SESSION['sid'];
	
	$boat_id = $_REQUEST['boat_id'];
	$date = ($_REQUEST['date']);

	if(!$boat_id )
	{	
		$error_msg = "Error - invalid boat.";
	}
	
	if( !$date )
	{	
		$error_msg = "Invalid date.";
	}
	
	if($error_msg)
	{
		header("Location:reservations.php?response_msg=".$error_msg);
		exit;
	}
	else
	{
		
		if( cancel_reservation($sailor_id, $boat_id, $date) )
		{
			header("Location:reservations.php?response_msg=Reservation cancelled.");
			exit;
		}
		else
		{
			header("Location:reservations.php?response_msg=An error has occurred. Reservation could not be cancelled.");
			exit;
		}
	}
?>